<?php
/**
 * Esta classe permite guardar uma lista de Updates de PersonAppData que será submetida em "batch mode" ao container.
 * 
 * @package    opensocial
 * @subpackage datarequest
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 */
class OSUpdatePersonAppDataRequest implements OSDataRequestable
{
  const NEWUPDATE_PERSONAPPDATA_REQUEST_PATTERN = "newUpdatePersonAppDataRequest(%s,%s,%s)";
  
  private $updateAppDataList = array();
  
  public function __construct()
  {
  }
  
  public function generateDataRequest(OSDataRequest $dataRequest)
  {
  	$request_var = $dataRequest->getDataRequestVarName();
  	$html = '';
  	
    foreach($this->updateAppDataList as $appData) {
      $html .= $request_var.".add(".$request_var.".".sprintf(OSUpdatePersonAppDataRequest::NEWUPDATE_PERSONAPPDATA_REQUEST_PATTERN,$appData->getPerson()->getType(),'"'.$appData->getKey().'"',$appData->getValue()).");\n";
    }
    return $html;
  }
  
  public function addPersonAppData(OSPersonAppData $appData)
  {
  	$this->updateAppDataList[] = $appData;
  }
  
  public function getOptionalKey()
  {
  	return null;
  }
  
  public function getUpdateAppDataList(){
  	return $this->updateAppDataList;
  }
  
}